package com.agen

import android.app.Application
import android.content.Context
import android.util.Log
import com.agen.basenet.util.ConnectManager
import com.agen.basenet.util.NetManager
import okhttp3.logging.HttpLoggingInterceptor

class App : Application() {

    override fun attachBaseContext(base: Context?) {
        super.attachBaseContext(base)

        val logInterceptor = HttpLoggingInterceptor().apply {
            level = HttpLoggingInterceptor.Level.BODY
        }
        NetManager.setDebug(true)
            .addInterceptor(logInterceptor)
            .setHost { "https://www.wanandroid.com/" }
    }

    override fun onCreate() {
        super.onCreate()

        ConnectManager.registerNetworkCallback(object : ConnectManager.Callback {
            override fun onAvailable() {
                Log.i("ConnectManager", "network onAvailable")
            }

            override fun onUnavailable() {
                Log.i("ConnectManager", "network onUnavailable")
            }
        })
    }
}